package priv.pfz.basedao.lab.performance;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @author yyjxp
 * 2024/8/4 15:35
 */
public class ReflectUtilMethod implements ReflectTest {
    private Method utilMethod;

    public ReflectUtilMethod() {
        try {
            utilMethod = TestBean.class.getMethod("callGetters", TestBean.class);
        } catch (NoSuchMethodException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public String name() {
        return "反射调用手写方法";
    }

    @Override
    public void run(TestBean bean) {
        try {
            utilMethod.invoke(null, bean);
        } catch (IllegalAccessException | InvocationTargetException e) {
            throw new RuntimeException(e);
        }
    }
}
